import bitbrowser_api as api
import log
import pyppeteer
import ai_api 
import asyncio
import random
import time

async def op_openpage(ws_link :str,url :str):
    try:
        # 连接到浏览器
        browser = await pyppeteer.connect(browserWSEndpoint=ws_link)
        # 打开新页面
        page = await browser.newPage()
        # 导航到指定 URL
        await page.goto(url)
        log.Info(f"成功打开网页:{url}")
    except Exception as e:
        log.Error(f"连接浏览器或打开网页失败: {str(e)}")
        return False

if __name__ == "__main__":
    ws_link = api.get_pyppeteer_wslink_by_ids(api.get_alive_ids()[0])
    url = "https://www.facebook.com/"
    asyncio.get_event_loop().run_until_complete(op_openpage(ws_link, url))